#!/usr/bin/env python3
# 详细验证第一财经截断功能

from app import fetch_full_content

def check_yicai_truncation():
    """检查第一财经截断功能的详细效果"""
    url = "https://www.yicai.com/news/102791233.html"
    print(f"🔍 检查URL: {url}")
    
    result = fetch_full_content(url)
    content = result.get('content', '')
    
    print(f"\n📊 内容长度: {len(content)}")
    
    # 检查各种问题内容是否被正确截断
    problematic_patterns = [
        '举报',
        '相关阅读', 
        '一财最热',
        'banquan@yicai.com',
        '文章作者',
        '<comment',
        '第一财经版权',
        '版权归第一财经所有'
    ]
    
    print("\n=== 截断效果检查 ===")
    for pattern in problematic_patterns:
        if pattern in content:
            pos = content.find(pattern)
            # 检查是否在截断标识附近
            surrounding = content[max(0, pos-100):pos+100]
            has_truncation_marker = '[内容在此截断' in surrounding
            
            if has_truncation_marker:
                print(f"⚠️  {pattern}: 存在但在截断标识附近")
            else:
                print(f"❌ {pattern}: 存在且未被截断")
                # 显示问题内容的上下文
                print(f"   上下文: ...{content[max(0, pos-50):pos+50]}...")
        else:
            print(f"✅ {pattern}: 已成功截断")
    
    # 检查截断标识
    print(f"\n📝 截断标识: {'✅' if '[内容在此截断' in content else '❌'}")
    
    # 显示内容末尾
    print(f"\n📄 内容末尾 (最后150字符):")
    print("-" * 50)
    print(content[-150:])
    print("-" * 50)
    
    return content

if __name__ == "__main__":
    check_yicai_truncation()